#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int a[26];
char x;
void solve()
{
	string s;
	cin >>s;
	memset(a, 0, sizeof a);
	vector<char> v;
	for (int i = 0; i < s.size(); i++)
	{
		v.push_back(s[i]);
		a[s[i] - 'a']++;
	}
	for (int i = 0; i < v.size(); i++)
	{
		if (a[v[i] - 'a'] > 1)
		{
			a[v[i] - 'a']--;
			continue;
		}
		if (a[v[i] - 'a'] == 1)
		{
			for(int j=i;j<v.size();j++) cout<<v[j];
			cout<<'\n';
			return;
		}
	}

}

int main()
{
	close();
	int T; cin >> T;
	while (T--) solve();
	return 0;
}
//首字符出现在字符串后面可以删掉首字符,问最后结果